﻿using Device;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace hejian_pcba_test.Procdure
{
    internal enum DevStatus
    {
        Wait,
        NG,
        OK
    }

    internal class Global
    {
        //伺服电机
        public static LC10P Motor { get; set; }

        public static IOModule IOModule { get; set; }
        public static Relay Relay { get; set; }

        private static void NGStatus()
        {
            //await Task.Run(async () =>
            //{
            while (Ng)
            {
                IOModule.SetDOValue((int)DODefine.RedLight, 1);
                Thread.Sleep(500);

                IOModule.SetDOValue((int)DODefine.RedLight, 0);
                Thread.Sleep(500);
            }
            //});
        }

        static bool Ng = false;

        public static void SetDevStatus(DevStatus status)
        {
            switch (status)
            {
                case DevStatus.Wait:
                    Ng = false;
                    Thread.Sleep(1000);
                    IOModule.SetDOValue((int)DODefine.YellowLight, 1);
                    IOModule.SetDOValue((int)DODefine.GreenLight, 0);
                    IOModule.SetDOValue((int)DODefine.RedLight, 0);

                    break;

                case DevStatus.NG:
                    Ng = true; ;
                    IOModule.SetDOValue((int)DODefine.YellowLight, 0);
                    IOModule.SetDOValue((int)DODefine.GreenLight, 0);
                    Task.Run(() => {
                        NGStatus();
                    });
                    break;

                case DevStatus.OK:
                    Ng = false;
                    Thread.Sleep(1000);
                    IOModule.SetDOValue((int)DODefine.RedLight, 0);
                    IOModule.SetDOValue((int)DODefine.GreenLight, 1);
                    IOModule.SetDOValue((int)DODefine.YellowLight, 0);
                    break;

                default:
                    break;
            }
        }
    }
}